package com.wf.ew.common;

import com.wf.ew.system.model.User;
import net.sf.json.JSONObject;
import org.apache.poi.ss.formula.functions.T;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

/**
 * Controller基类
 * Created by wangfan on 2017-6-10 上午10:10
 */
public class BaseController {

    /**
     * 获取当前登录的user
     */
    public User getLoginUser() {
        Subject subject = SecurityUtils.getSubject();
        if (subject != null) {
            Object object = subject.getPrincipal();
            if (object != null) {
                return (User) object;
            }
        }
        return null;
    }

    /**
     * 获取当前登录的userId
     */
    public String getLoginUserId() {
        User loginUser = getLoginUser();
        return loginUser == null ? null : loginUser.getId();
    }
    public String getResultMap(String result, Object data2, String message) {
        JSONObject data = new JSONObject();
        data.put("result", result);
        data.put("data", data2);
        data.put("message", message);
        return data.toString();
    }
    public String getPageResult(PageResult<T> page) {
        JSONObject data = new JSONObject();
        data.put("count", page.getCount());
        data.put("data", page.getData());
        data.put("msg", "请输入正确的提单号");
        data.put("code", 0);
        return data.toString();
    }
}
